Skip to content

[16.0][FIX] fastapi: Flush before exiting Fastapi environment#542

Merged
OCA-git-bot merged 1 commit into
OCA:16.0from
acsone:oca-port-fastapi-17.0-to-16.0-6a673e
Jun 16, 2025
Merged

[16.0][FIX] fastapi: Flush before exiting Fastapi environment#542
OCA-git-bot merged 1 commit into
OCA:16.0from
acsone:oca-port-fastapi-17.0-to-16.0-6a673e

Conversation

@lmignon

@lmignon lmignon commented Jun 16, 2025

Copy link
Copy Markdown
Contributor

As the fastapi dispatcher is altering the public request's environment before calling the endpoint, it will reuse the same DB cursor from this environment.

Therefore, if fields are being marked to be recomputed during the execution of the fastapi endpoint, these will not be recomputed until the cursor is being commited, what happens when we are not anymore authenticated through as fastapi user. This means the recomputation of computed fields will be executed with the public user, what could potentially lead to inconsistencies or result in an AccessError.

By calling flush before exiting the contextmanager yielding the altered Odoo environment, we ensure all the pending computations are executed while being authenticated with the fastapi user which must have more access rights than the public user.

backport of #538

As the fastapi dispatcher is altering the public request's
environment before calling the endpoint, it will reuse
the same DB cursor from this environment.

Therefore, if fields are being marked to be recomputed during
the execution of the fastapi endpoint, these will not be
recomputed until the cursor is being commited, what happens
when we are not anymore authenticated through as fastapi user.
This means the recomputation of computed fields will be executed
with the public user, what could potentially lead to inconsistencies
or result in an AccessError.

By calling flush before exiting the contextmanager yielding
the altered Odoo environment, we ensure all the pending
computations are executed while being authenticated with
the fastapi user which must have more access rights than the
public user.
@lmignon lmignon added this to the 16.0 milestone Jun 16, 2025
@lmignon

lmignon commented Jun 16, 2025

Copy link
Copy Markdown
Contributor Author

/ocabot merge patch

@OCA-git-bot

Copy link
Copy Markdown
Contributor

What a great day to merge this nice PR. Let's do it!
Prepared branch 16.0-ocabot-merge-pr-542-by-lmignon-bump-patch, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit 5fe5dcd into OCA:16.0 Jun 16, 2025
7 checks passed
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at 4a64027. Thanks a lot for contributing to OCA. ❤️

@lmignon lmignon deleted the oca-port-fastapi-17.0-to-16.0-6a673e branch June 16, 2025 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants